# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: main.py
# Time: 10:11

import os
import time
import threading
import pytest

from common.utils.file_util import get_case_dir
from common.utils.file_util import get_real_output_dir



# allure = os.path.join(get_time_report(), "allure")
# allure_report = os.path.join(get_time_report(), "allue_report")

class MyThread(threading.Thread):
    def __init__(self,*args):
        threading.Thread.__init__(self)
        self.thre = tuple(*args)[0]
        self.name = tuple(*args)[1]
        # self.name = tuple(*args)[2]

    def run(self):
        # 重写run方法
        print(f"开始线程：{self.name}")
        run(self.thre)
        print(f"结束线程：{self.name}")


def run(times):
    allure = os.path.join(get_real_output_dir("report"), times, "allure")
    allure_report = os.path.join(get_real_output_dir("report"), times, "allue_report")
    # 执行pytest单元测试，生成aluure报告存在report目录中
    pytest.main(["-s", "-v", get_case_dir("user_test"), "--alluredir", allure])
    os.system(f"allure generate {allure} -o {allure_report} --clean")


if __name__ == '__main__':
    s = [("noe", "1"),("two","2")]
    threads = []
    for i in s:
        threads.append(MyThread(i))
    for e in threads:
        e.start()
    for q in threads:
        q.join()


